//
//  AEGoodsDetailViewController.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/14.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEGoodsDetailViewController.h"
#import "AEGoodsDetailViewModel.h"
#import "AE_Solar-Swift.h"
#import "AEGoodsDetailBottomView.h"
#import "AEGoodsDetailInfoView.h"
#import "AEGoodsDetailRuleView.h"
#import "AESubmitOrderViewController.h"

@interface AEGoodsDetailViewController ()
@property (nonatomic, strong) AEGoodsDetailViewModel *viewModel;

/// 基本信息
@property (nonatomic, strong) AEGoodsDetailInfoView *baseInfoView;

/// 规则视图
@property (nonatomic, strong) AEGoodsDetailRuleView *goodsRuleView;


@property (nonatomic, strong) AEGoodsDetailBottomView *bottomView;



/// 基本信息
- (void)initWithBaseInfoView;

/// 规则视图
- (void)initWithGoodsRuleView;

@end

@implementation AEGoodsDetailViewController

- (void)dealloc {
    debugMethod();
}

- (void)initWithVar {
    [super initWithVar];
    
}

- (void)initWithViewModel {
    _viewModel = [AEGoodsDetailViewModel new];
    [_viewModel setupData];
}

- (void)initWithNavBar {
    [super initWithNavBar];
    
    [self initWithBackButton];
    
    self.navigationItem.title = self.viewModel.title;
}

- (void)initWithSubView {
    [super initWithSubView];
    
    [self initWithRootContent:NO];
    self.rootContent.height = kScreenH - NAVBAR_HEIGHT_STATUS - kAEGoodsDetailBottomViewHeight;
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    self.rootContent.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    
    /// 基本信息
    [self initWithBaseInfoView];

    /// 规则视图
    [self initWithGoodsRuleView];
    
    [self initWithBottomView];
    
    self.rootContent.contentSize = CGSizeMake(kScreenW, self.goodsRuleView.bottom + 20);
}

/// 基本信息
- (void)initWithBaseInfoView {
    if (!_baseInfoView) {
        CGRect frame = CGRectMake(0, 0, kScreenW, kAEGoodsDetailInfoViewHeight);
        _baseInfoView = [[AEGoodsDetailInfoView alloc] initWithFrame:frame];
        [self.rootContent addSubview:_baseInfoView];
    }
    [self.baseInfoView updateWithViewData:self.viewModel];
}

/// 规则视图
- (void)initWithGoodsRuleView {
    if (!_goodsRuleView) {
        CGRect frame = CGRectMake(0, self.baseInfoView.bottom + 10, kScreenW, kAEGoodsDetailRuleViewHeight);
        _goodsRuleView = [[AEGoodsDetailRuleView alloc] initWithFrame:frame];
        [self.rootContent addSubview:_goodsRuleView];
    }
    [self.goodsRuleView updateWithViewData:nil];
}


- (void)initWithBottomView {
    if (!_bottomView) {
        CGRect frame = CGRectMake(0, self.rootContent.bottom, kScreenW, kAEGoodsDetailBottomViewHeight);
        _bottomView = [[AEGoodsDetailBottomView alloc] initWithFrame:frame];
        [self.view addSubview:_bottomView];
        
        @weakify(self);
        // 立即兑换
        _bottomView.touchImmediateExchangeBlock = ^{
            @strongify(self);
            [self actionWithImmediateExchange];
        };
    }
}

/// 立即兑换
- (void)actionWithImmediateExchange {
//    [SVProgressHUD showInfoWithStatus:@"立即兑换"];
    AESubmitOrderViewController *orderVC = [[AESubmitOrderViewController alloc] init];
    [TYZJumpVCManager pushBaseVC:self pushVC:orderVC];
}



@end
